﻿#include "stdafx.h"
#include "XLayoutIntParser.h"

#include "XBSTR.h"
#include "StrUtil.h"
#include "Util.h"
#include "IXLayout.h"

CXLayoutIntParser::CXLayoutIntParser() : CXIntParserBase(&TIntCreateControl<IXLayout>)
{
    ;
}

CXLayoutIntParser::~CXLayoutIntParser()
{
    ;
}

// 填充属性
BOOL CXLayoutIntParser::FillAttr(IN IXConfigNode* pNode, IN IXControl* pControl)
{
    BOOL bResult = m_ParentParser.FillAttr(pNode, pControl);
    if(!bResult)
        return bResult;

    XBSTR bstrTemp;
    BOOL bTemp;
    LONG lTemp;

    IXLayout* pLayout = Util::QueryIntf<IXLayout>(pControl);
    if(pLayout == NULL)
        return FALSE;

    pLayout->SetLayoutable(FALSE);

    // LayoutType
    if(SUCCEEDED(pNode->GetValue(_T("type"), &bstrTemp)))
    {
        if(_tcsicmp(bstrTemp, _T("horz")) == 0)
            pLayout->SetLayoutType(Layout_Horz);
        else if(_tcsicmp(bstrTemp, _T("vert")) == 0)
            pLayout->SetLayoutType(Layout_Vert);
    }

    // TODO: ChildMargin

    // EnableScrollBar
    if(SUCCEEDED(pNode->GetValue(_T("enablesb"), &bTemp)))
    {
        pLayout->EnableScrollBar(bTemp);
    }

    // ScrollLine
    if(SUCCEEDED(pNode->GetValue(_T("scrollLine"), &lTemp)))
    {
        pLayout->SetScrollLine(lTemp);
    }

    return bResult;
}

BOOL CXLayoutIntParser::PostCreate(IN IXConfigNode* pNode, IN IXControl* pControl)
{
    BOOL bResult = m_ParentParser.PostCreate(pNode, pControl);

    IXLayout* pLayout = Util::QueryIntf<IXLayout>(pControl);
    if(pLayout == NULL)
        return FALSE;

    pLayout->SetLayoutable(TRUE);

    return bResult;
}
